package com.faithbj.device.service.impl;

import javax.annotation.Resource;

import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.faithbj.device.dao.ConsumableDao;
import com.faithbj.device.model.configuration.Pager;
import com.faithbj.device.model.entity.Consumable;
import com.faithbj.device.service.ConsumableService;

@Service("consumableService")
@Transactional
public class ConsumableServiceImpl implements ConsumableService {
	
	@Resource
	private ConsumableDao conDao;

	@Override
	public Pager findByPager(Pager pager) {
		return conDao.findByPager(pager);
	}

	@Override
	public Consumable load(String id) {
		return conDao.load(id);
	}

	@Override
	public Consumable get(String id) {
		return conDao.get(id);
	}

	@Override
	public void update(Consumable persistent) {
		conDao.update(persistent);
	}

	@Override
	public void save(Consumable con) {
		conDao.save(con);
	}

	@Override
	public void delete(String id) {
		conDao.delete(id);
	}

	@Override
	public Consumable findByCode(String code) {
		return conDao.get("sn", code);
	}

	@Override
	public boolean hasSn(String oldValue, String newSn) {
		if (StringUtils.equalsIgnoreCase(oldValue, newSn))
		      return true;
		    return !(findByCode(newSn)!=null);
	}

}
